#include "UiCalculator.h"
#ifdef MERGER_APP_TO_SHELL
	extern HINSTANCE g_SDHResModuleHandle;
#endif
UiCalculator::UiCalculator()
{
}

UiCalculator::~UiCalculator()
{
}

BOOL UiCalculator::InitUiWin(void)
{
	BOOL bRtn = FALSE;
//	SetWindowLong(m_hWnd, GWL_USERDATA, (LONG) this);
	LoadiInterItem();
	InitImages();
	return bRtn;
}

void UiCalculator::PaintWin(HDC hdc, RECT* prcWin, RECT* prcUpdate)
{
	m_CalculatorBG->Draw(hdc, prcWin, false, false);
}

int UiCalculator::OnLButtonDown(UINT fwKeys, int xPos, int yPos)
{
	return UiWin::OnLButtonDown(fwKeys, xPos, yPos);

}

int UiCalculator::OnLButtonUp(UINT fwKeys, int xPos, int yPos)
{
	return UiWin::OnLButtonUp(fwKeys, xPos, yPos);

}

void UiCalculator::LoadiInterItem()
{
//jdhuang 20120818
#ifndef MERGER_APP_TO_SHELL
	m_DownBarBG = ImagingHelper::GetImageObject(MzGetInstanceHandle(), 1063);
#else
	m_CalculatorBG = ImagingHelper::GetImageObject(g_SDHResModuleHandle, 8540);
#endif
	RECT rtBtnCalculator[] = {
		8, 19, 114, 85,

		10, 102, 114, 168,
		116, 102, 220, 168,
		223, 102, 327, 168,
		325, 102, 438, 168,
		435, 102, 539, 168,

		10, 167, 114, 233,
		116, 167, 220, 233,
		223, 167, 327, 233,
		325, 167, 438, 233,
		435, 167, 539, 233,
	
		10, 231, 114, 297,
		116, 231, 220, 297,
		223, 231, 327, 297,
		325, 231, 438, 297,

		10, 297, 114, 363,
		116, 297, 220, 363,
		223, 297, 327, 363,
		325, 297, 438, 363,
		
		435, 231, 539, 363,
	};
	m_BtnCalculator[CALCULATOR_CLOSE].SetPos(rtBtnCalculator[CALCULATOR_CLOSE].left, rtBtnCalculator[CALCULATOR_CLOSE].top,
					rtBtnCalculator[CALCULATOR_CLOSE].right-rtBtnCalculator[CALCULATOR_CLOSE].left,
					rtBtnCalculator[CALCULATOR_CLOSE].bottom-rtBtnCalculator[CALCULATOR_CLOSE].top);
	m_BtnCalculator[CALCULATOR_CLOSE].SetID(7510);
	m_BtnCalculator[CALCULATOR_CLOSE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8515, true));
	m_BtnCalculator[CALCULATOR_CLOSE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8535, true));
	AddChild(&m_BtnCalculator[CALCULATOR_CLOSE]);

	m_BtnCalculator[CALCULATOR_NUM_SEVEN].SetPos(rtBtnCalculator[CALCULATOR_NUM_SEVEN].left, rtBtnCalculator[CALCULATOR_NUM_SEVEN].top,
					rtBtnCalculator[CALCULATOR_NUM_SEVEN].right-rtBtnCalculator[CALCULATOR_NUM_SEVEN].left,
					rtBtnCalculator[CALCULATOR_NUM_SEVEN].bottom-rtBtnCalculator[CALCULATOR_NUM_SEVEN].top);
	m_BtnCalculator[CALCULATOR_NUM_SEVEN].SetID(7507);
	m_BtnCalculator[CALCULATOR_NUM_SEVEN].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8507, true));
	m_BtnCalculator[CALCULATOR_NUM_SEVEN].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8527, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_SEVEN]);

	m_BtnCalculator[CALCULATOR_NUM_EIGHT].SetPos(rtBtnCalculator[CALCULATOR_NUM_EIGHT].left, rtBtnCalculator[CALCULATOR_NUM_EIGHT].top,
					rtBtnCalculator[CALCULATOR_NUM_EIGHT].right-rtBtnCalculator[CALCULATOR_NUM_EIGHT].left,
					rtBtnCalculator[CALCULATOR_NUM_EIGHT].bottom-rtBtnCalculator[CALCULATOR_NUM_EIGHT].top);
	m_BtnCalculator[CALCULATOR_NUM_EIGHT].SetID(7508);
	m_BtnCalculator[CALCULATOR_NUM_EIGHT].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8508, true));
	m_BtnCalculator[CALCULATOR_NUM_EIGHT].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8528, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_EIGHT]);

	m_BtnCalculator[CALCULATOR_NUM_NINE].SetPos(rtBtnCalculator[CALCULATOR_NUM_NINE].left, rtBtnCalculator[CALCULATOR_NUM_NINE].top,
					rtBtnCalculator[CALCULATOR_NUM_NINE].right-rtBtnCalculator[CALCULATOR_NUM_NINE].left,
					rtBtnCalculator[CALCULATOR_NUM_NINE].bottom-rtBtnCalculator[CALCULATOR_NUM_NINE].top);
	m_BtnCalculator[CALCULATOR_NUM_NINE].SetID(7509);
	m_BtnCalculator[CALCULATOR_NUM_NINE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8509, true));
	m_BtnCalculator[CALCULATOR_NUM_NINE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8529, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_NINE]);

	m_BtnCalculator[CALCULATOR_CLEAN_ONE].SetPos(rtBtnCalculator[CALCULATOR_CLEAN_ONE].left, rtBtnCalculator[CALCULATOR_CLEAN_ONE].top,
					rtBtnCalculator[CALCULATOR_CLEAN_ONE].right-rtBtnCalculator[CALCULATOR_CLEAN_ONE].left,
					rtBtnCalculator[CALCULATOR_CLEAN_ONE].bottom-rtBtnCalculator[CALCULATOR_CLEAN_ONE].top);
	m_BtnCalculator[CALCULATOR_CLEAN_ONE].SetID(7511);
	m_BtnCalculator[CALCULATOR_CLEAN_ONE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8519, true));
	m_BtnCalculator[CALCULATOR_CLEAN_ONE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8539, true));
	AddChild(&m_BtnCalculator[CALCULATOR_CLEAN_ONE]);

	m_BtnCalculator[CALCULATOR_CLEAN_ALL].SetPos(rtBtnCalculator[CALCULATOR_CLEAN_ALL].left, rtBtnCalculator[CALCULATOR_CLEAN_ALL].top,
					rtBtnCalculator[CALCULATOR_CLEAN_ALL].right-rtBtnCalculator[CALCULATOR_CLEAN_ALL].left,
					rtBtnCalculator[CALCULATOR_CLEAN_ALL].bottom-rtBtnCalculator[CALCULATOR_CLEAN_ALL].top);
	m_BtnCalculator[CALCULATOR_CLEAN_ALL].SetID(7512);
	m_BtnCalculator[CALCULATOR_CLEAN_ALL].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8518, true));
	m_BtnCalculator[CALCULATOR_CLEAN_ALL].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8538, true));
	AddChild(&m_BtnCalculator[CALCULATOR_CLEAN_ALL]);

	m_BtnCalculator[CALCULATOR_NUM_FOUR].SetPos(rtBtnCalculator[CALCULATOR_NUM_FOUR].left, rtBtnCalculator[CALCULATOR_NUM_FOUR].top,
					rtBtnCalculator[CALCULATOR_NUM_FOUR].right-rtBtnCalculator[CALCULATOR_NUM_FOUR].left,
					rtBtnCalculator[CALCULATOR_NUM_FOUR].bottom-rtBtnCalculator[CALCULATOR_NUM_FOUR].top);
	m_BtnCalculator[CALCULATOR_NUM_FOUR].SetID(7504);
	m_BtnCalculator[CALCULATOR_NUM_FOUR].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8504, true));
	m_BtnCalculator[CALCULATOR_NUM_FOUR].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8524, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_FOUR]);

	m_BtnCalculator[CALCULATOR_NUM_FIVE].SetPos(rtBtnCalculator[CALCULATOR_NUM_FIVE].left, rtBtnCalculator[CALCULATOR_NUM_FIVE].top,
					rtBtnCalculator[CALCULATOR_NUM_FIVE].right-rtBtnCalculator[CALCULATOR_NUM_FIVE].left,
					rtBtnCalculator[CALCULATOR_NUM_FIVE].bottom-rtBtnCalculator[CALCULATOR_NUM_FIVE].top);
	m_BtnCalculator[CALCULATOR_NUM_FIVE].SetID(7505);
	m_BtnCalculator[CALCULATOR_NUM_FIVE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8505, true));
	m_BtnCalculator[CALCULATOR_NUM_FIVE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8525, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_FIVE]);

	m_BtnCalculator[CALCULATOR_NUM_SIX].SetPos(rtBtnCalculator[CALCULATOR_NUM_SIX].left, rtBtnCalculator[CALCULATOR_NUM_SIX].top,
					rtBtnCalculator[CALCULATOR_NUM_SIX].right-rtBtnCalculator[CALCULATOR_NUM_SIX].left,
					rtBtnCalculator[CALCULATOR_NUM_SIX].bottom-rtBtnCalculator[CALCULATOR_NUM_SIX].top);
	m_BtnCalculator[CALCULATOR_NUM_SIX].SetID(7506);
	m_BtnCalculator[CALCULATOR_NUM_SIX].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8506, true));
	m_BtnCalculator[CALCULATOR_NUM_SIX].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8526, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_SIX]);

	m_BtnCalculator[CALCULATOR_MULTIPLY].SetPos(rtBtnCalculator[CALCULATOR_MULTIPLY].left, rtBtnCalculator[CALCULATOR_MULTIPLY].top,
					rtBtnCalculator[CALCULATOR_MULTIPLY].right-rtBtnCalculator[CALCULATOR_MULTIPLY].left,
					rtBtnCalculator[CALCULATOR_MULTIPLY].bottom-rtBtnCalculator[CALCULATOR_MULTIPLY].top);
	m_BtnCalculator[CALCULATOR_MULTIPLY].SetID(7513);
	m_BtnCalculator[CALCULATOR_MULTIPLY].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8510, true));
	m_BtnCalculator[CALCULATOR_MULTIPLY].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8530, true));
	AddChild(&m_BtnCalculator[CALCULATOR_MULTIPLY]);

	m_BtnCalculator[CALCULATOR_DIVIDE].SetPos(rtBtnCalculator[CALCULATOR_DIVIDE].left, rtBtnCalculator[CALCULATOR_DIVIDE].top,
					rtBtnCalculator[CALCULATOR_DIVIDE].right-rtBtnCalculator[CALCULATOR_DIVIDE].left,
					rtBtnCalculator[CALCULATOR_DIVIDE].bottom-rtBtnCalculator[CALCULATOR_DIVIDE].top);
	m_BtnCalculator[CALCULATOR_DIVIDE].SetID(7514);
	m_BtnCalculator[CALCULATOR_DIVIDE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8511, true));
	m_BtnCalculator[CALCULATOR_DIVIDE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8531, true));
	AddChild(&m_BtnCalculator[CALCULATOR_DIVIDE]);

	m_BtnCalculator[CALCULATOR_NUM_ONE].SetPos(rtBtnCalculator[CALCULATOR_NUM_ONE].left, rtBtnCalculator[CALCULATOR_NUM_ONE].top,
					rtBtnCalculator[CALCULATOR_NUM_ONE].right-rtBtnCalculator[CALCULATOR_NUM_ONE].left,
					rtBtnCalculator[CALCULATOR_NUM_ONE].bottom-rtBtnCalculator[CALCULATOR_NUM_ONE].top);
	m_BtnCalculator[CALCULATOR_NUM_ONE].SetID(7501);
	m_BtnCalculator[CALCULATOR_NUM_ONE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8501, true));
	m_BtnCalculator[CALCULATOR_NUM_ONE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8521, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_ONE]);

	m_BtnCalculator[CALCULATOR_NUM_TWO].SetPos(rtBtnCalculator[CALCULATOR_NUM_TWO].left, rtBtnCalculator[CALCULATOR_NUM_TWO].top,
					rtBtnCalculator[CALCULATOR_NUM_TWO].right-rtBtnCalculator[CALCULATOR_NUM_TWO].left,
					rtBtnCalculator[CALCULATOR_NUM_TWO].bottom-rtBtnCalculator[CALCULATOR_NUM_TWO].top);
	m_BtnCalculator[CALCULATOR_NUM_TWO].SetID(7502);
	m_BtnCalculator[CALCULATOR_NUM_TWO].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8502, true));
	m_BtnCalculator[CALCULATOR_NUM_TWO].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8522, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_TWO]);

	m_BtnCalculator[CALCULATOR_NUM_THREE].SetPos(rtBtnCalculator[CALCULATOR_NUM_THREE].left, rtBtnCalculator[CALCULATOR_NUM_THREE].top,
					rtBtnCalculator[CALCULATOR_NUM_THREE].right-rtBtnCalculator[CALCULATOR_NUM_THREE].left,
					rtBtnCalculator[CALCULATOR_NUM_THREE].bottom-rtBtnCalculator[CALCULATOR_NUM_THREE].top);
	m_BtnCalculator[CALCULATOR_NUM_THREE].SetID(7503);
	m_BtnCalculator[CALCULATOR_NUM_THREE].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8503, true));
	m_BtnCalculator[CALCULATOR_NUM_THREE].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8523, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_THREE]);

	m_BtnCalculator[CALCULATOR_SUBTRACT].SetPos(rtBtnCalculator[CALCULATOR_SUBTRACT].left, rtBtnCalculator[CALCULATOR_SUBTRACT].top,
					rtBtnCalculator[CALCULATOR_SUBTRACT].right-rtBtnCalculator[CALCULATOR_SUBTRACT].left,
					rtBtnCalculator[CALCULATOR_SUBTRACT].bottom-rtBtnCalculator[CALCULATOR_SUBTRACT].top);
	m_BtnCalculator[CALCULATOR_SUBTRACT].SetID(7515);
	m_BtnCalculator[CALCULATOR_SUBTRACT].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8517, true));
	m_BtnCalculator[CALCULATOR_SUBTRACT].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8537, true));
	AddChild(&m_BtnCalculator[CALCULATOR_SUBTRACT]);

	m_BtnCalculator[CALCULATOR_ROOT].SetPos(rtBtnCalculator[CALCULATOR_ROOT].left, rtBtnCalculator[CALCULATOR_ROOT].top,
					rtBtnCalculator[CALCULATOR_ROOT].right-rtBtnCalculator[CALCULATOR_ROOT].left,
					rtBtnCalculator[CALCULATOR_ROOT].bottom-rtBtnCalculator[CALCULATOR_ROOT].top);
	m_BtnCalculator[CALCULATOR_ROOT].SetID(7516);
	m_BtnCalculator[CALCULATOR_ROOT].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8514, true));
	m_BtnCalculator[CALCULATOR_ROOT].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8534, true));
	AddChild(&m_BtnCalculator[CALCULATOR_ROOT]);

	m_BtnCalculator[CALCULATOR_NUM_ZERO].SetPos(rtBtnCalculator[CALCULATOR_NUM_ZERO].left, rtBtnCalculator[CALCULATOR_NUM_ZERO].top,
					rtBtnCalculator[CALCULATOR_NUM_ZERO].right-rtBtnCalculator[CALCULATOR_NUM_ZERO].left,
					rtBtnCalculator[CALCULATOR_NUM_ZERO].bottom-rtBtnCalculator[CALCULATOR_NUM_ZERO].top);
	m_BtnCalculator[CALCULATOR_NUM_ZERO].SetID(7500);
	m_BtnCalculator[CALCULATOR_NUM_ZERO].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8500, true));
	m_BtnCalculator[CALCULATOR_NUM_ZERO].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8520, true));
	AddChild(&m_BtnCalculator[CALCULATOR_NUM_ZERO]);

	m_BtnCalculator[CALCULATOR_DOT].SetPos(rtBtnCalculator[CALCULATOR_DOT].left, rtBtnCalculator[CALCULATOR_DOT].top,
					rtBtnCalculator[CALCULATOR_DOT].right-rtBtnCalculator[CALCULATOR_DOT].left,
					rtBtnCalculator[CALCULATOR_DOT].bottom-rtBtnCalculator[CALCULATOR_DOT].top);
	m_BtnCalculator[CALCULATOR_DOT].SetID(7517);
	m_BtnCalculator[CALCULATOR_DOT].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8513, true));
	m_BtnCalculator[CALCULATOR_DOT].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8533, true));
	AddChild(&m_BtnCalculator[CALCULATOR_DOT]);

	m_BtnCalculator[CALCULATOR_ADD].SetPos(rtBtnCalculator[CALCULATOR_ADD].left, rtBtnCalculator[CALCULATOR_ADD].top,
					rtBtnCalculator[CALCULATOR_ADD].right-rtBtnCalculator[CALCULATOR_ADD].left,
					rtBtnCalculator[CALCULATOR_ADD].bottom-rtBtnCalculator[CALCULATOR_ADD].top);
	m_BtnCalculator[CALCULATOR_ADD].SetID(7518);
	m_BtnCalculator[CALCULATOR_ADD].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8516, true));
	m_BtnCalculator[CALCULATOR_ADD].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8536, true));
	AddChild(&m_BtnCalculator[CALCULATOR_ADD]);

	m_BtnCalculator[CALCULATOR_EQUAL].SetPos(rtBtnCalculator[CALCULATOR_EQUAL].left, rtBtnCalculator[CALCULATOR_EQUAL].top,
					rtBtnCalculator[CALCULATOR_EQUAL].right-rtBtnCalculator[CALCULATOR_EQUAL].left,
					rtBtnCalculator[CALCULATOR_EQUAL].bottom-rtBtnCalculator[CALCULATOR_EQUAL].top);
	m_BtnCalculator[CALCULATOR_EQUAL].SetID(7519);
	m_BtnCalculator[CALCULATOR_EQUAL].SetNormalImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8512, true));
	m_BtnCalculator[CALCULATOR_EQUAL].SetPressedImage(ImagingHelper::GetImageObject(g_SDHResModuleHandle,8532, true));
	AddChild(&m_BtnCalculator[CALCULATOR_EQUAL]);



	RECT rtArithmetic = {116, 19, 539, 85};
	m_StaticArithmetic.SetPos(rtArithmetic.left, rtArithmetic.top, rtArithmetic.right-rtArithmetic.left, rtArithmetic.bottom-rtArithmetic.top);
//	m_StaticArithmetic.SetText(L"0");
	m_StaticArithmetic.SetTextSize(32);
	m_StaticArithmetic.SetTextColor(RGB(255, 255, 255));
	AddChild(&m_StaticArithmetic);

}

BOOL UiCalculator::InitImages()
{
/*
	HDC hDC = GetDC(m_hWnd);
//jdhuang

	RECT rcClient = GetClientRect();
//	GetClientRect(m_hWnd, &rcClient);

	m_hBakDC = CreateCompatibleDC(hDC);

	m_hBitmapBakDC = CreateCompatibleBitmap(hDC, RECT_WIDTH(rcClient), RECT_HEIGHT(rcClient));
	SelectObject(m_hBakDC, m_hBitmapBakDC);

	//jdhuang 20090616
//	HDC hMemDc = CreateCompatibleDC(m_hBakDC);

	if(m_DownBarBG)
	{
		m_DownBarBG->Draw(m_hBakDC, &rcClient, false, false);
//		DeleteDC(hMemDc);
	}
	ReleaseDC(m_hWnd, hDC);
*/
	return TRUE;
}
void UiCalculator::DeleteImages()
{
	m_CalculatorBG->UnloadImage();
}